package laya.semi.process;

import java.util.*;
import java.text.*;

import org.apache.log4j.Logger;

public class ArrayIterator
	implements Iterator
{
	private static Logger log = Logger.getLogger(ArrayIterator.class);

	private int m_nIndex = 0;
	private Map m_oFieldMap = new HashMap();
	private int m_nSize = -1;
	
	public void addField(String oFieldName, Object[] vFieldArray)
	{
		if (vFieldArray.length > m_nSize)
			m_nSize = vFieldArray.length;
		
		m_oFieldMap.put(oFieldName, vFieldArray);
	}

	public boolean hasNext()
	{
		return m_nIndex < m_nSize;
	}

	public Object next() 
	{
		if (!hasNext())
			throw new NoSuchElementException();
			
		Map e = new HashMap();
		Set oKeySet = m_oFieldMap.keySet();
		for (Iterator it = oKeySet.iterator(); it.hasNext(); )
		{
			Object oKey = it.next();
			Object[] vArray = (Object[])m_oFieldMap.get(oKey);
			Object val = (m_nIndex < vArray.length ? vArray[m_nIndex] : null);
			e.put(oKey, val);
		}
		
		++m_nIndex;
		return e;
	}

	public void remove()
	{
		throw new UnsupportedOperationException();
	}
	
}
